package com.hongdee.insurance.contract.mapper;

import com.hongdee.insurance.contract.pojo.TInsuranceCompanyContractPojo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * Created by Liu XiaoLong
 * Date: 2017/11/10.
 * Remark:
 */
@Mapper
public interface TInsuranceCompanyContractMapper {

    @SelectProvider(type = TInsuranceCompanyContractQuery.class,method = "list")
//    @Select("select c.*,p.province provinceName,i.city cityName from t_insurance_company_contract c " +
//            "left join t_bc_provinces p on c.province = p.provinceid " +
//            "left JOIN t_bc_cities i on c.city =CONVERT(i.cityid USING utf8) COLLATE utf8_unicode_ci " +
//            "where c.`year`=#{data.year} and c.area=#{data[1]} and c.insurance_company_id = #{data[2]} ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "contract_no", property = "contractNo"),
            @Result(column = "insurance_company_id", property = "insuranceCompanyId"),
            @Result(column = "type", property = "type"),
            @Result(column = "year", property = "year"),
            @Result(column = "area", property = "area"),
            @Result(column = "length_number", property = "lengthNumber"),
            @Result(column = "common_type", property = "commonType"),
            @Result(column = "city", property = "city"),
            @Result(column = "province", property = "province"),
            @Result(column = "provinceName", property = "provinceName"),
            @Result(column = "cityName", property = "cityName")
    })
    List<TInsuranceCompanyContractPojo> list(@Param("data") Map data);


    /**
     * 更新实体
     */
    @Update("update t_insurance_company_contract set area=#{area}, contract_no= #{contractNo},insurance_company_id = #{insuranceCompanyId}" +
            ",type = #{type},length_number = #{lengthNumber},commonType = #{commonType},city = {city},province =#{province},  year = #{year}," +
            "status=#{status},areas=#{areas} where id = #{id}")
    void UpdatePoJo(TInsuranceCompanyContractPojo tInsuranceCompanyContractPojo);

    @Insert("insert into t_insurance_company_contract (id,area,contract_no,insurance_company_id,status,year,type,length_number,common_type,city,province,areas)values(#{id}," +
            "#{area},#{contractNo},#{insuranceCompanyId},#{status},#{year},#{type},#{lengthNumber},#{commonType},#{city},#{province},#{areas})")
        //@SelectKey(statement = "select  replace(uuid(),'-','')   from dual", keyProperty = "id", before = true, resultType = String.class)
    void Insert(TInsuranceCompanyContractPojo tInsuranceCompanyContractPojo);

    @Update("update t_insurance_company_contract set status= #{status} where id = #{id}")
    void updateStatus(@Param("status") String status,@Param("id") String id);

    @Select("select * from t_insurance_company_contract where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "contract_no", property = "contractNo"),
            @Result(column = "insurance_company_id", property = "insuranceCompanyId"),
            @Result(column = "type", property = "type"),
            @Result(column = "year", property = "year"),
            @Result(column = "area", property = "area")
    })
    TInsuranceCompanyContractPojo Info(@Param("id") String id);

    @Select("select * from t_insurance_company_contract where contract_no = #{contractNo} and area = #{area} and insurance_company_id = #{insuranceCompany}" +
            " and year = #{year} and common_type = #{commonType} and type = #{type} and areas = #{areas}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "contract_no", property = "contractNo"),
            @Result(column = "insurance_company_id", property = "insuranceCompanyId"),
            @Result(column = "type", property = "type"),
            @Result(column = "year", property = "year"),
            @Result(column = "area", property = "area")
    })
    List<TInsuranceCompanyContractPojo> getContractNoList(@Param("contractNo") String contractNo
            ,@Param("area") String area
            ,@Param("insuranceCompany") String insuranceCompany
            ,@Param("year") String year
            ,@Param("commonType") String commonType
            ,@Param("type") String type
            ,@Param("areas") String areas);

    @Select("select * from t_insurance_company_contract where common_type = #{commonType} and area = #{area} and insurance_company_id = #{insuranceCompany} and year = #{year}  and type = #{type}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "contract_no", property = "contractNo"),
            @Result(column = "insurance_company_id", property = "insuranceCompanyId"),
            @Result(column = "type", property = "type"),
            @Result(column = "year", property = "year"),
            @Result(column = "area", property = "area")
    })
    List<TInsuranceCompanyContractPojo> getListOnArea (@Param("commonType") String commonType,@Param("area") String area
            ,@Param("insuranceCompany") String insuranceCompany
            ,@Param("year") String year
            ,@Param("type") String type);

}
